import { NzMessageService } from 'ng-zorro-antd'
import { I18NService } from '@core'
import { EChargeOperateBodyI18n } from '@shared/interfaces/operation'

export abstract class OperateBaseAbstractClass {

  constructor(
    public msg: NzMessageService,
    public i18n: I18NService,
  ) {}

  public checkValidAndShowMsg(formObj): boolean {
    const errorKeys = []
    let isValid = true
    for (const key in formObj) {
      if (formObj[key] === undefined && EChargeOperateBodyI18n[key]) {
        errorKeys.push(this.trans(EChargeOperateBodyI18n[key]))
        isValid = false
      }
    }
    if (!isValid) {
      this.msg.error(this.trans('VALIDATION.REQUIRED', { name: `${errorKeys.join('、')}`}))
    }
    return isValid
  }

  trans(key: string, params?: Object): string {
    return this.i18n.fanyi(key, params)
  }
}
